﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Golos.BackEnd.Client;
using Golos.Polls.PollCache;
using Golos.Users.UserCache;

namespace Golos.ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
             *A1 5BFD7DA8-0FD6-43D4-AD35-9EB35A312A90
              A2 80922BED-BF8D-4573-8F32-E5F5461B3D6D
              Q B7BA7B06-1191-456F-9609-E68C0E98A486
              U 20691290-7184-47EF-BBA1-07DFF8851EF9
             */
            PollsClient pollClient = new PollsClient(new Uri("http://127.0.0.1:9998"));
            pollClient.GetTop10Question();
            /*
            UsersClient client = new UsersClient(new Uri("http://127.0.0.1:9999"));
            UserInfo info = client.GetUserInfoByUserId(new Guid("31654918-8244-4AE2-9A2E-E9D9314EC5EB"));
            info.Name = "Гена Алексеев";
            info.Email = "gena.alexeev@gmail.com";
            client.UpdateProfile(info);
            Console.ReadKey();
             */ 
        }

        static void PerfTest()
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            int i = 0;
            while (i<10000)
            {
                TagsClient tagsClient = new TagsClient(new Uri("http://127.0.0.1:9997"));
                PollsClient pollClient = new PollsClient(new Uri("http://127.0.0.1:9998"));
                UsersClient userClient = new UsersClient(new Uri("http://127.0.0.1:9999"));
                pollClient.GetTop10Question();
                pollClient.GetPollInfo(new Guid("86826bd1-85b2-40f7-ab10-0810ee757473"));
                pollClient.GetVoicesCount(new Guid("86826bd1-85b2-40f7-ab10-0810ee757473"));
                pollClient.GetUserAnswerInfo(new Guid("86826bd1-85b2-40f7-ab10-0810ee757473"),
                                             new Guid("eef2156b-0b2c-4a39-ad62-f3b255b6e328"));
                pollClient.GetVotedQuestions(new Guid("eef2156b-0b2c-4a39-ad62-f3b255b6e328"));
                pollClient.GetUserQuestions(new Guid("eef2156b-0b2c-4a39-ad62-f3b255b6e328"));
                tagsClient.GetPopularTags();
                tagsClient.GetQuestionTags(new Guid("86826bd1-85b2-40f7-ab10-0810ee757473"));
                i++;
            }
            stopwatch.Stop();
            Console.WriteLine(i);
            Console.WriteLine(stopwatch.Elapsed);
        }

        static void Vote()
        {
            UserAnswerInfo answerInfo = new UserAnswerInfo(new Guid("20691290-7184-47EF-BBA1-07DFF8851EF9"), new Guid("B7BA7B06-1191-456F-9609-E68C0E98A486"), new Guid("5BFD7DA8-0FD6-43D4-AD35-9EB35A312A90"));
            AnswerProperties answerProperties = new AnswerProperties(new Guid("5BFD7DA8-0FD6-43D4-AD35-9EB35A312A90"), "127.0.0.1", true);
            PollsClient client = new PollsClient(new Uri("http://127.0.0.1:9998"));
            client.Vote(answerInfo, answerProperties);
        }

        static void CreatePoll()
        {
            PollInfo pollInfo = new PollInfo(new Guid("20691290-7184-47EF-BBA1-07DFF8851EF9"), "Кто будет призедентом?", new List<Answer>() { new Answer(Guid.NewGuid(), "Путин", 1), new Answer(Guid.NewGuid(), "Жирик", 2) });
            PollsClient client = new PollsClient(new Uri("http://127.0.0.1:9998"));
            client.CreatePoll(pollInfo);
        }

        static void RegistrationTest()
        {
            UsersClient client = new UsersClient(new Uri("http://127.0.0.1:9999"));
            Console.WriteLine(string.Format("Register user: {0} = {1}", UserIdType.VK, "4860425"));
            Guid userId = client.RegisterUser(UserIdType.VK, "4860421");
            Console.WriteLine(string.Format("Return UserId = {0}", userId));
            Console.WriteLine("Get UserInfo by userId:");
            UserInfo userInfo = client.GetUserInfoByUserId(userId);
            Console.WriteLine(string.Format("UserId: {0}", userInfo.Id));
            Console.WriteLine(string.Format("Name: {0}", userInfo.Name));
            Console.WriteLine(string.Format("Email: {0}", userInfo.Email));
            foreach (var key in userInfo.UserIdentification.Keys)
            {
                Console.WriteLine(string.Format("UserIdType: {0}", key));
                Console.WriteLine(string.Format("IdentificationId: {0}", userInfo.UserIdentification[key]));
            }
        }
    }
}
